from django.db import models

# Create your models here.

class PinDao(models.Model):
  name = models.CharField(max_length=20)
  url = models.URLField()
  
  title = models.CharField(max_length=100)
  des = models.CharField(max_length=250)
  keywords = models.CharField(max_length=250, blank=True, null=True)
  
  page_last_updated_at = models.DateTimeField(blank=True, null=True)
  
  def __unicode__(self):
    return self.name
  
  def get_html_file_name(self):
    return '%s.html'%self.name
  fn = property(fget=get_html_file_name)
  
  def get_latest_page(self):
    n = self.page_set.count()
    if n > 0:
      return self.page_set.order_by('-created_at')[0]
    return None
  latest_page = property(fget=get_latest_page)
  
class Page(models.Model):
  content = models.TextField(blank=True, null=True)  
  created_at = models.DateTimeField(auto_now_add=True)
  
  md5 = models.CharField(max_length=100)
  pindao = models.ForeignKey('PinDao')
  
  def __unicode__(self):
    return ''

